# -*- coding: utf-8 -*-
'''
@author: Hugo
@file: demo1.py
@time: 2021/8/11 23:40
'''
import json
import openpyxl as xl
from mitmproxy import ctx

wb = xl.Workbook()
ws = wb.create_sheet('wyh', index = 0)
ws.append(['标题', '城市', '详情'])

def request(flow):
    request = flow.request
    # request.url = 'http://www.baidu.com'
    info = ctx.log.info
    info(request.url)
    # ctx.log.warn(request.host+'sdfefasdfadf>>>>>>>>>>>>>>>>>')

def response(flow):
    response = flow.response
    info = ctx.log.info
    print(str(response.cookies))
    # ctx.log.warn(response.text)
    if 'api/post/Query?timestamp' in flow.request.url:
        data = json.loads(response.text)
        for i in data['Data']['Posts']:
            ctx.log.error(str(i))
            title = i.get('RecruitPostName')
            LocationName = i.get('LocationName')
            Responsibility = i.get('Responsibility')
            print(title)
            '''
            xlwt   operpyxl   pandas  csv
            '''
        #     ws.append([title,LocationName,Responsibility])
        # wb.save('wyh1.xlsx')



#  https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1628702643123&countryId=&cityId=&bgIds=&productId=&categoryId=4000
# 6&parentCategoryId=&attrId=&keyword=&pageIndex=3&pageSize=10&language=zh-cn&area=cn